home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Apple II Magazines (PO)
/
Nibble Volume 09, No. 06 (1988-06)(MicroSPARC)(Side A).zip
/
Nibble Volume 09, No. 06 (1988-06)(MicroSPARC)(Side A).po
/
APM.S
< prev
next >
Wrap
Text File
|
1996-12-24
|
8KB
|
197 lines
***************************
* APPLESOFT PROGRAM MOVER *
* BY MIKE MIYAKE *
***************************
PAGE EQU 6 holds dest. page #
TEMP EQU 7 holds source page - dest.page
LINK EQU 8 holds link field addresses
A1 EQU $3C source block start ptr.for move
A2 EQU $3E source end ptr.for move
A4 EQU $42 dest.ptr for move
TXTTAB EQU $67 start of BASIC program ptr.
VARTAB EQU $69 start of variables ptr.
ARYTAB EQU $6B start of array space ptr.
STREND EQU $6D end of array storage ptr.
FRETOP EQU $6F bottom of strings ptr.
VARPNT EQU $83 general storage
PGREND EQU $AF end of program ptr.
TXTPTR EQU $B8 address being interpreted
PTR EQU $CE
MOVE EQU $FE2C monitor move routine
;----------------------------
ORG $8E00
;----------------------------
LDA PAGE get page #
STA A4+1 insert in dest.
CMP #8 is dest.page too low?
BCC BADPAGE yes, then exit
SBC TXTTAB+1 find difference
STA TEMP save it
CLC
ADC STREND+1
CMP FRETOP+1 is dest.page too high?
BCC GOOD no, then branch & begin
BADPAGE RTS
GOOD LDY #0 set MOVE parms
STY A1
STY A4
INY
STY LINK set link field ptrs
LDA TXTTAB+1
STA A1+1
STA LINK+1
LDA STREND copy STREND for MOVE
STA A2
LDA STREND+1
STA A2+1
LDA VARTAB
STA PTR copy VARTAB
LDY VARTAB+1
STY PTR+1
L1 CMP ARYTAB end of simple variables?
LDA PTR+1
SBC ARYTAB+1
BCS L5 yes, branch to do arrays
LDY #0
LDA (PTR),Y fetch 1st byte of var.name
BMI L2 if neg, it may be a FN
INY if pos, fetch next byte--
LDA (PTR),Y must be neg.to be string
BPL L4 if pos, branch to get next var
LDY #4
BPL L3
L2 INY (FN's)
LDA (PTR),Y 2nd byte of FN must be pos
BMI L4 else branch to get next var.
LDY #3
CLC
LDA (PTR),Y adjust FN argument ptr.
ADC TEMP
STA (PTR),Y
LDY #5
L3 LDA (PTR),Y get FN formula/string ptr
CMP FRETOP+1 is it a string literal or FN?
BCS L4 no, then get next variable
ADC TEMP adjust ptr.to FN/string
STA (PTR),Y
L4 CLC get ptr.to next variable
LDA PTR
ADC #7 simple vars.stored in 7 bytes
STA PTR
BCC L1
INC PTR+1
BCS L1 always branch
L5 LDA PTR begin to process arrays
CMP STREND has end of arrays been reached?
LDA PTR+1
SBC STREND+1
BCS L12 yes, branch to do BASIC ptrs
LDY #2 no, get offset to next array
CLC
LDA PTR
STA VARPNT save ptr.to current array
ADC (PTR),Y add offset to next array
PHA
INY
LDA PTR+1
STA VARPNT+1
ADC (PTR),Y
STA PTR+1 and save ptr.to next array
PLA
STA PTR
LDY #0
LDA (VARPNT),Y fetch 1st byte in var.name
BMI L5 if neg, it's not a string--branch
INY
LDA (VARPNT),Y fetch 2nd byte
BPL L5 if pos, it's not a string--branch
LDY #4 (check string arrays only)
LDA (VARPNT),Y fetch # of indices
ASL 2 bytes/index
BCC L6
INC VARPNT+1 find zeroth element:
CLC
L6 ADC VARPNT add header location to
BCC L7 2 * the # of indices
INC VARPNT+1
CLC
L7 ADC #5 plus 5 bytes overhead
STA VARPNT save in VARPNT
BCC L8
INC VARPNT+1
L8 LDY #2 get MSB of ptr
L9 LDA (VARPNT),Y
CMP FRETOP+1 is string a literal?
BCS L10 no, get next element
ADC TEMP yes, adjust ptrs
STA (VARPNT),Y
L10 CLC fetch next element
LDA VARPNT
ADC #3 3 bytes each
STA VARPNT
BCC L11
INC VARPNT+1
L11 CMP PTR all elements done?
LDA VARPNT+1
SBC PTR+1
BCC L9 no, get another
BCS L5 yes, get next array
L12 LDX #8
L13 DEX
CLC
LDA TXTTAB,X reset BASIC pointers:
ADC TEMP TXTTAB, VARTAB,ARYTAB,
STA TXTTAB,X STREND
DEX
BNE L13
CLC
LDA PGREND+1 adjust end of program ptr
ADC TEMP
STA PGREND+1
LDA TXTPTR+1 adjust text pointer
CMP #2 but only if program is running
BEQ L14
CLC
ADC TEMP
STA TXTPTR+1
L14 LDY #0
LDA (LINK),Y reset link field addresses
TAX fetch & save ptr to next addr
INY
LDA (LINK),Y get MSB of addr
BEQ L15 if it's a zero, branch--we're done
PHA save it
CLC
ADC TEMP adjust it
STA (LINK),Y put it back in the program
STX LINK install ptrs. saved earlier
PLA
STA LINK+1
BNE L14 branch always
L15 DEY
LDA PAGE
CMP A1+1 is move up or down?
BCS L16 if up, branch
JMP MOVE else use monitor MOVE & exit
L16 LDA STREND+1 set dest. ptrs
STA A4+1
LDA STREND
STA A4
L17 LDA (A2),Y fetch a byte off the top
STA (A4),Y move it
SEC
LDA A2 adjust pointers
SBC #1
STA A4
STA A2
BCS L18
DEC A4+1
DEC A2+1
L18 CMP A1 are we done?
LDA A2+1
SBC A1+1
BCS L17 if carry set, go back & repeat
RTS if carry clear, we're done